//
// Created by jsjxsy on 2022/9/13.
//
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
class myPrint {
 public:
  void operator()(int val) {
    cout << val << " ";
  }
};

void test01() {
  vector<int> v1;
  vector<int> v2;
  for (int i = 0; i < 10; i++) {
    v1.push_back(i);
    v2.push_back(i + 5);
  }
  cout << "v1:" << endl;
  for_each(v1.begin(), v1.end(), myPrint());
  cout << endl;

  cout << "v2:" << endl;
  for_each(v2.begin(), v2.end(), myPrint());
  cout << endl;

  vector<int> vTarget;
  //取两个容器的和给目标容器开辟空间
  vTarget.resize(v1.size() + v2.size());

  //返回目标容器的最后一个元素的迭代器地址
  vector<int>::iterator itEnd =
      set_union(v1.begin(), v1.end(), v2.begin(), v2.end(), vTarget.begin());
  cout << "v1与v2的并集:" << endl;
  for_each(vTarget.begin(), itEnd, myPrint());
  cout << endl;
}

int main() {
  test01();
  return 0;
}
